package org.swidgets.base.spanels;

import org.swidgets.base.BorderStyle;
import org.swidgets.base.HTMLInjector;

import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * 
 * Internal Class
 *
 */
public class SSimpleFrame extends Grid{
	private Panel mainPanel= new SimplePanel();; 
		
	public SSimpleFrame(){
		super(3,3);
		setBorderWidth(0);
		setCellPadding(0);
		setCellSpacing(0);	
		CellFormatter cf=getCellFormatter();
		cf.setStyleName(0, 0, "tableCorner");
		cf.setStyleName(0, 2, "tableCorner");
		cf.setStyleName(2, 0, "tableCorner");
		cf.setStyleName(2, 2, "tableCorner");
		this.addStyleName("fontZero");
	}
	
	public void setStyle(BorderStyle style){		
		this.setStyleName(style.getMain());
		String left= style.getLeft();
		String right= style.getRight();
		CellFormatter cf=getCellFormatter();
		cf.setStyleName(0, 1, style.getTop());
		cf.setStyleName(2, 1, style.getBottom());
		cf.setStyleName(1, 0, left);
		cf.setStyleName(1, 2, right);
		cf.setStyleName(1, 1, style.getContent());		
//		
//		//setting corners imgs
//
		HTMLInjector.imgInject(cf.getElement(0, 0), style.getUrlImgTopLeft());
		HTMLInjector.imgInject(cf.getElement(0, 2), style.getUrlImgTopRight());
		HTMLInjector.imgInject(cf.getElement(2, 0), style.getUrlImgBottomLeft());
		HTMLInjector.imgInject(cf.getElement(2, 2), style.getUrlImgBottomRight());

		this.addStyleName("fontZero");

	}

	public void add(Widget child) {
		mainPanel.add(child);
		this.setWidget(1, 1, mainPanel);		
	}


	public void setBodyWidget(Widget w){
		this.setWidget(1, 1, w);
	}
	
	
	
	public void clearContent(){
		this.clearCell(1, 1);
	}
		
	public Widget getBodyWidget(){
		return this.getWidget(1, 1);
	}
	
	public Element getContainer(){
		return this.getWidget(1, 1).getElement();
	}
	
	
	public void setCellStyle(int row,int column,String style){
		this.getWidget(row, column).setStyleName(style);
	}
}
